
package org.openeai.lite.console.actionhandlers;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.apache.log4j.Logger;
import org.openeai.lite.common.control.BrokerController;
import org.openeai.lite.common.exception.OpenEAIException;
import org.openeai.lite.common.model.Queue;
import org.openeai.lite.common.model.Topic;


@ManagedBean(name = "brokerDeleteDestinationActionHandler")
@RequestScoped
public class BrokerDeleteDestinationActionHandler
{

    private static Logger log = Logger.getLogger(BrokerDeleteDestinationActionHandler.class);

    // properties
    private Queue queue;

    private Topic topic;

    public void setQueue(Queue queue)
    {
        this.queue = queue;
    }

    public Queue getQueue()
    {
        return this.queue;
    }

    // Topic getter & setter
    public Topic getTopic()
    {
        return topic;
    }

    public void setTopic(Topic topic)
    {
        this.topic = topic;
    }

    // Delete Queue
    public void deleteQueue() throws OpenEAIException
    {
        try
        {
            if (this.queue != null)
            {
                BrokerController.getInstance().deleteQueue(queue);
                this.queue = null;
            }
            else
            {
                log.error("Cannot retreive queue for deleting.");
            }
        }
        catch (OpenEAIException oeu)
        {
            // handling and logging is done by backend logic
            ;
        }
    }

    // Delete Topic
    public void deleteTopic() throws OpenEAIException
    {
        try
        {
            if (this.topic != null)
            {
                BrokerController.getInstance().deleteTopic(topic);
                this.topic = null;
            }
            else
            {
                log.error("Cannot retreive topic for deleting.");
            }
        }
        catch (OpenEAIException oeu)
        {
            // handling and logging is done by backend logic
            ;
        }
    }
}
